Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Bootstrap logic in tests #7252

Merged
merged 3 commits into from
Mar 3, 2020
Merged

Simplify Bootstrap logic in tests #7252

merged 3 commits into from
Mar 3, 2020

Conversation

notnoop
Copy link
Contributor

@notnoop notnoop commented Mar 3, 2020

This change updates tests to honor BootstrapExpect exclusively when
forming test clusters and removes test only knobs, e.g.
config.DevDisableBootstrap.

Background

Test cluster creation is fragile. Test servers don't follow the
BootstapExpected route like production clusters. Instead they start as
single node clusters and then get rejoin and may risk causing brain
split or other test flakiness.

The test framework expose few knobs to control those (e.g.
config.DevDisableBootstrap and config.Bootstrap) that control
whether a server should bootstrap the cluster. These flags are
confusing and it's unclear when to use: their usage in multi-node
cluster isn't properly documented. Furthermore, they have some bad
side-effects as they don't control Raft library: If
config.DevDisableBootstrap is true, the test server may not
immediately attempt to bootstrap a cluster, but after an election
timeout (~50ms), Raft may force a leadership election and win it (with
only one vote) and cause a split brain.

The knobs are also confusing as Bootstrap is an overloaded term. In
BootstrapExpect, we refer to bootstrapping the cluster only after N
servers are connected. But in tests and the knobs above, it refers to
whether the server is a single node cluster and shouldn't wait for any
other server.

Changes

This commit makes two changes:

First, it relies on BootstrapExpected instead of Bootstrap and/or
DevMode flags. This change is relatively trivial.

Introduce a Bootstrapped flag to track if the cluster is bootstrapped.
This allows us to keep BootstrapExpected immutable. Previously, the
flag was a config value but it gets set to 0 after cluster bootstrap
completes.

Notes

@langmartin attempted a different strategy in 2b16278 but resulted into a wackamo game fixing tests.

Fixes #7239

Mahmood Ali added 2 commits March 2, 2020 13:47
This change updates tests to honor `BootstrapExpect` exclusively when
forming test clusters and removes test only knobs, e.g.
`config.DevDisableBootstrap`.

Background:

Test cluster creation is fragile.  Test servers don't follow the
BootstapExpected route like production clusters.  Instead they start as
single node clusters and then get rejoin and may risk causing brain
split or other test flakiness.

The test framework expose few knobs to control those (e.g.
`config.DevDisableBootstrap` and `config.Bootstrap`) that control
whether a server should bootstrap the cluster.  These flags are
confusing and it's unclear when to use: their usage in multi-node
cluster isn't properly documented.  Furthermore, they have some bad
side-effects as they don't control Raft library: If
`config.DevDisableBootstrap` is true, the test server may not
immediately attempt to bootstrap a cluster, but after an election
timeout (~50ms), Raft may force a leadership election and win it (with
only one vote) and cause a split brain.

The knobs are also confusing as Bootstrap is an overloaded term.  In
BootstrapExpect, we refer to bootstrapping the cluster only after N
servers are connected.  But in tests and the knobs above, it refers to
whether the server is a single node cluster and shouldn't wait for any
other server.

Changes:

This commit makes two changes:

First, it relies on `BootstrapExpected` instead of `Bootstrap` and/or
`DevMode` flags.  This change is relatively trivial.

Introduce a `Bootstrapped` flag to track if the cluster is bootstrapped.
This allows us to keep `BootstrapExpected` immutable.  Previously, the
flag was a config value but it gets set to 0 after cluster bootstrap
completes.
The tests only care if a test server recognizes the leader.
@notnoop notnoop requested a review from langmartin March 3, 2020 01:40
@notnoop notnoop self-assigned this Mar 3, 2020
@@ -446,7 +433,7 @@ func TestNomad_BadExpect(t *testing.T) {
testutil.WaitForResult(func() (bool, error) {
for _, s := range servers {
p, _ := s.numPeers()
if p != 1 {
if p != 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a change in behavior. When using bootstrap, the peers list remains empty until cluster is fully bootstrapped. Previously, servers will at least recognize themselves as a peer.

Copy link
Contributor

@langmartin langmartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me, looks like this is how these flags were originally designed. I love eliminating a test-only special path

nomad/config.go Outdated
// required so that it can elect a leader without any other nodes
// being present
Bootstrap bool
// Bootstrapped indictes if Server has bootstrapped or not.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling: indicates

@notnoop notnoop merged commit d7896b9 into master Mar 3, 2020
@notnoop notnoop deleted the b-test-cluster-forming branch March 3, 2020 21:56
tgross added a commit that referenced this pull request Mar 4, 2020
In #7252 we removed the `DevDisableBootstrap` flag to require tests to
honor only `BootstrapExpect`, in order to reduce a source of test
flakiness. This changeset applies the same fix to the CSI tests.
tgross added a commit that referenced this pull request Mar 4, 2020
In #7252 we removed the `DevDisableBootstrap` flag to require tests to
honor only `BootstrapExpect`, in order to reduce a source of test
flakiness. This changeset applies the same fix to the CSI tests.
tgross added a commit that referenced this pull request Mar 9, 2020
In #7252 we removed the `DevDisableBootstrap` flag to require tests to
honor only `BootstrapExpect`, in order to reduce a source of test
flakiness. This changeset applies the same fix to the CSI tests.
langmartin pushed a commit that referenced this pull request Mar 13, 2020
In #7252 we removed the `DevDisableBootstrap` flag to require tests to
honor only `BootstrapExpect`, in order to reduce a source of test
flakiness. This changeset applies the same fix to the CSI tests.
tgross added a commit that referenced this pull request Mar 16, 2020
In #7252 we removed the `DevDisableBootstrap` flag to require tests to
honor only `BootstrapExpect`, in order to reduce a source of test
flakiness. This changeset applies the same fix to the CSI tests.
tgross added a commit that referenced this pull request Mar 23, 2020
In #7252 we removed the `DevDisableBootstrap` flag to require tests to
honor only `BootstrapExpect`, in order to reduce a source of test
flakiness. This changeset applies the same fix to the CSI tests.
tgross added a commit that referenced this pull request Mar 23, 2020
In #7252 we removed the `DevDisableBootstrap` flag to require tests to
honor only `BootstrapExpect`, in order to reduce a source of test
flakiness. This changeset applies the same fix to the CSI tests.
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TestLeader_ClusterID_noUpgrade flaky test
2 participants